package cn.shengongying.api.vo;

import cn.shengongying.model.BossOrder;
import cn.shengongying.model.BossPosition;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author : RXK
 * Date : 2021-7-24 18:02
 * Code Less Think More
 * Desc:
 */
@Getter
@Setter
public class OrderListVo extends PositionVo {

    private static final long serialVersionUID = 5851881952180746581L;

    @ApiModelProperty(value = "支付时间(时间戳)")
    private Long payTime;

    @ApiModelProperty(value = "总金额")
    private String totalAmount;


    @ApiModelProperty(value = "发票状态(0:招聘中/全额退款,不可申请开票;1:开票中;2:开票完成)")
    private Integer invoiceStatus;

    @ApiModelProperty(value = "退款状态(0:招聘中,不可申请退款;1:退款中;2:退款完成)")
    private Integer status;

    @ApiModelProperty(value = "职位状态(0:招聘中;1:招满,自动下架;2:招满,手动下架)")
    private Integer positionStatus;


    public static List<OrderListVo> list(List<BossOrder> orderList, List<BossPosition> positionList) {
        return orderList.stream()
                .map(bossOrder -> {
                    OrderListVo vo = new OrderListVo();
                    vo.setId(bossOrder.getId());
                    vo.setTotalAmount(bossOrder.getActualAmount()
                            .toString());
                    vo.setPayTime(bossOrder.getPaySuccessTime()
                            .getTime());


                    positionList.stream()
                            .filter(position -> bossOrder.getExtId()
                                    .compareTo(position.getId()) == 0)
                            .findFirst()
                            .ifPresent(position -> {
                                vo.setType(position.getType());
                                vo.setPositionName(position.getPositionName());
                                vo.setPeopleNum(position.getPeopleNum());


                                if (position.getStatus() == 2) {
                                    vo.setStatus(0);
                                } else if (bossOrder.getStatus() == 3) {
                                    vo.setStatus(1);
                                } else if (bossOrder.getStatus() == 4 || bossOrder.getStatus() == 5) {
                                    vo.setStatus(2);
                                }

                                if (position.getStatus() == 2) {
                                    vo.setStatus(0);
                                } else if (bossOrder.getInvoiceStatus() == 2) {
                                    vo.setInvoiceStatus(1);
                                } else if (bossOrder.getInvoiceStatus() == 3) {
                                    vo.setInvoiceStatus(2);
                                }

                                if (position.getStatus() == 2) {
                                    vo.setPositionStatus(0);
                                } else if (position.getStatus() == 3) {
                                    vo.setPositionStatus(1);
                                } else if (position.getStatus() == 4) {
                                    vo.setPositionStatus(2);
                                }

                                if (position.getStatus() == 2) {
                                    vo.setInvoiceStatus(0);
                                } else if (bossOrder.getInvoiceStatus() == 2) {
                                    vo.setInvoiceStatus(1);
                                } else if (bossOrder.getInvoiceStatus() == 3) {
                                    vo.setInvoiceStatus(2);
                                }

                            });
                    return vo;
                })
                .collect(Collectors.toList());
    }
}
